#include <InputEventReceiver.h>

bool KeyIsJustPressed[KEY_KEY_CODES_COUNT];
//------------------------------------------------------------------------
// Konstruktor
//------------------------------------------------------------------------
InputEventReceiver::InputEventReceiver()
{
	for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i){
		KeyIsDown[i] = false;
		KeyIsJustPressed[i] = false;
	}
}
//------------------------------------------------------------------------
// Destruktor
//------------------------------------------------------------------------
InputEventReceiver::~InputEventReceiver()
{
}
//------------------------------------------------------------------------
// Methoden
//------------------------------------------------------------------------
bool InputEventReceiver::OnEvent(const SEvent& event)
{
	// Remember whether each key is down or up
	if (event.EventType == irr::EET_KEY_INPUT_EVENT){
		KeyIsJustPressed[event.KeyInput.Key] = (KeyIsDown[event.KeyInput.Key] != event.KeyInput.PressedDown) && event.KeyInput.PressedDown;
		KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
	}

	if (event.EventType == irr::EET_MOUSE_INPUT_EVENT)
	{
		switch(event.MouseInput.Event)
		{
		case EMIE_LMOUSE_PRESSED_DOWN:
			MouseState.LeftButtonDown = true;
			break;

		case EMIE_LMOUSE_LEFT_UP:
			MouseState.LeftButtonDown = false;
			break;

		case EMIE_RMOUSE_PRESSED_DOWN:
			MouseState.RightButtonDown = true;
			break;

		case EMIE_RMOUSE_LEFT_UP:
			MouseState.RightButtonDown = false;
			break;

		default:
			// We won't use the wheel
			break;
		}
	}

	return false;
}
//------------------------------------------------------------------------
bool InputEventReceiver::IsKeyDown(EKEY_CODE keyCode) const
{
	return KeyIsDown[keyCode];
}

bool InputEventReceiver::IsKeyJustPressed(EKEY_CODE keyCode) const
{
	bool key = KeyIsJustPressed[keyCode];
	if(KeyIsJustPressed[keyCode]) KeyIsJustPressed[keyCode] = false;
	return key;
}
//------------------------------------------------------------------------
const InputEventReceiver::SMouseState & InputEventReceiver::GetMouseState(void) const
{
	return MouseState;
}
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//------------------------------------------------------------------------

